package com.eagle.coders.core.exceptions;

import java.sql.Timestamp;

public class BaseSystemException extends RuntimeException {

	private static final long serialVersionUID = 1L;

	private boolean isLogged = false;
    private String errorMessageLocation = null; // where to find error message properties file (resource bundle)
    private String messageKey = null; // to identify which error message in the resource bundle
    private String errorCode = null; // code to identify each types of error
    private Timestamp exceptionTimestamp = null; // timestamp of when the exception happens
    /*
     * This argument array is used in front-end for displaying proper concatenated
     * message to user, using pattern (retrieved from resource bundle) compatible 
     * with java.text.MessageFormat.
     */
    private Object[] messageArgs = null;

    //=============================================================================================
    // Constructors
    //=============================================================================================

    public BaseSystemException() {
    }

    public BaseSystemException(String msg) {
        super(msg);
    }

    public BaseSystemException(String msg, Throwable cause) {
        super(msg, cause);
    }

    public BaseSystemException(Throwable cause) {
        super(cause);
    }

    //  ---------------------------------------------------------------------------------------------
    // Below are similar set of constructors, but with Error Category & Code and its
    // corresponding pattern arguments for user-aware message purpose.

    public BaseSystemException(String errorMessageLocation, String messageKey, String errorCode, Object[] msgArgs) {
        this.errorMessageLocation = errorMessageLocation;
        this.messageKey = messageKey;
        this.messageArgs = msgArgs;
        this.errorCode = errorCode;
        this.exceptionTimestamp = new Timestamp(System.currentTimeMillis());
    }

    public BaseSystemException(String msg, String errorMessageLocation, String messageKey, String errorCode,
            Object[] msgArgs) {
        super(msg);
        this.errorMessageLocation = errorMessageLocation;
        this.messageKey = messageKey;
        this.messageArgs = msgArgs;
        this.errorCode = errorCode;
        this.exceptionTimestamp = new Timestamp(System.currentTimeMillis());
    }

    public BaseSystemException(String msg, Throwable cause, String errorMessageLocation,
            String messageKey, String errorCode, Object[] msgArgs) {
        super(msg, cause);
        this.errorMessageLocation = errorMessageLocation;
        this.messageKey = messageKey;
        this.messageArgs = msgArgs;
        this.errorCode = errorCode;
        this.exceptionTimestamp = new Timestamp(System.currentTimeMillis());
    }

    public BaseSystemException(Throwable cause, String errorMessageLocation, String messageKey, String errorCode,
            Object[] msgArgs) {
        super(cause);
        this.errorMessageLocation = errorMessageLocation;
        this.messageKey = messageKey;
        this.messageArgs = msgArgs;
        this.errorCode = errorCode;
        this.exceptionTimestamp = new Timestamp(System.currentTimeMillis());
    }

    //-------------------------------------------------------------------------

    public void setLogged() {
        isLogged = true;
    }

    public boolean isLogged() {
        return isLogged;
    }

    public String getErrorMessageLocation() {
        return errorMessageLocation;
    }

    public String getMessageKey() {
        return messageKey;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public Object[] getMessageArguments() {
        return messageArgs;
    }

    public Timestamp getExceptionTimestamp() {
        return exceptionTimestamp;
    }
}
